home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / DESKTOP / CLIPBOARD.ZIP / !Clipboard / !RunImage (.txt) < prev    next >
RISC OS BBC BASIC V Source  |  1998-09-17  |  13KB  |  546 lines

  1.  >Prog:!Clipboard.!RunImage
  2. $+" (error code "+
  3.  scrap 256
  4.  InternalHandle% = -&11223344
  5.  TASK 5,temp_name 12, menu_block 28+24*2
  6. $TASK="TASK"
  7.  "Wimp_Initialise",200,!TASK,"Clipboard" 
  8.  ,Handle%
  9.  "Wimp_OpenTemplate",,"<Obey$Dir>.Templates"
  10.  block 1024
  11. $temp_name="Info"
  12.  "Wimp_LoadTemplate",,0,,,-1,temp_name,0 
  13.  ,,IndSize%
  14.  indbuf IndSize%
  15.  "Wimp_LoadTemplate",,block,indbuf,indbuf+IndSize%+1,-1,temp_name,0
  16.  "Wimp_CreateWindow",,block 
  17.  InfoWindow%
  18. $temp_name="Main"
  19.  "Wimp_LoadTemplate",,0,,,-1,temp_name,0 
  20.  ,,IndSize%
  21.  indbuf IndSize%
  22.  "Wimp_LoadTemplate",,block,indbuf,indbuf+IndSize%+1,-1,temp_name,0
  23.  "Wimp_CreateWindow",,block 
  24.  MainWindow%
  25. block!0=-1
  26. block!4=0
  27. block!8=0
  28. block!12=76
  29. block!16=68
  30. block!20=%11000000011010
  31. $(block+24)="!Clipboard"
  32.  "Wimp_CreateIcon",,block
  33. SaveDragTo%=-1
  34.  =Quit%=
  35. :Owner%=-1:OurFile$="":SaveRef%=-1:SaveDragRef%=-1
  36. init_menu
  37. examine_clipboard
  38.  "Wimp_Poll",%110001,block 
  39.  Reason%
  40.  Reason% 
  41. &-    
  42.  2     : 
  43.  "Wimp_OpenWindow",,block
  44. '.    
  45.  3     : 
  46.  "Wimp_CloseWindow",,block
  47. (5    
  48.  6     : 
  49.  block!8<>2 
  50. mouse_click 
  51. )     
  52.  7     : 
  53. user_drag_box
  54. *!    
  55.  8     : 
  56.  block!24=13 
  57. +9                   
  58. save_clipboard(
  59. read_data(3),
  60.                  
  61. -'                   
  62.  block!24=&1B 
  63. .,                     
  64. close(MainWindow%)
  65.                    
  66. 07                     
  67.  "Wimp_ProcessKey", block!24
  68.                    
  69.                  
  70. 3'    
  71.  9     : 
  72.  block!0=1 
  73.  Quit%=
  74. 4$    
  75.  17,18 : 
  76. message(block!16)
  77.  19    : 
  78.  Quit%
  79.  "Wimp_CloseDown",Handle%,!TASK
  80.  "OS_Exit"
  81. message(Code%)
  82.  Code% 
  83.  0   : Quit%=
  84.  1   : 
  85.  block!12=SaveRef% 
  86. save_ack_to(SavePath$):
  87. @?             
  88.  block!12=MyRef% 
  89.  block!24=InternalHandle% 
  90. A'               
  91.  block!12<>MyRef% 
  92. B;                 
  93. pe("Bad yourref in DataSave message")
  94.                
  95. D2                 
  96.  block!24<>InternalHandle% 
  97. E<                   
  98. pe("Bad handle in DataSave message")
  99.                  
  100. G,                   
  101. proto("Found owner")
  102.                  
  103.                
  104. K0               
  105. set_text(3,
  106. strip(block+44))
  107. L=               
  108. set_text(6,
  109. name(block!4)):Owner%=block!4
  110. M#               Type$=
  111. ~block!40
  112. N,               
  113. set_text(2,
  114. type(Type$))
  115. O3               
  116. set_ind(0,"sfile_"+Type$+";r2")
  117. P4               
  118.  "Wimp_GetCaretPosition",,block
  119. Q<               
  120.  block!0=MainWindow% 
  121. put_caret(block)
  122. R6               
  123. unshade(3):
  124. unshade(0):
  125. unshade(4)
  126. S*               
  127. unshade(6):
  128. unshade(2)
  129.              
  130.  2   : 
  131.  block!12=SaveDragRef% 
  132. VL               
  133.  Dragged-to app wants the file - grab it from clip owner
  134. W'               SaveDragRef%=block!8
  135. Y5               
  136.  Ack the message whatever happens
  137. Z*               block!12 = SaveDragRef%
  138. [<               
  139.  "Wimp_SendMessage", 19, block, block!4
  140. ]8               
  141. save_clipboard(
  142. strip(block+44),
  143. ^%               
  144.  Owner%=Handle% 
  145. _+                 
  146.  We own it - ack now.
  147. `#                 
  148. send_save_ack
  149.                
  150.              
  151. c6               
  152. copy(OurFile$, 
  153. strip(block + 44))
  154. d#               Request%=block!4
  155. e#               block!12=block!8
  156.                block!16=3
  157. gJ               
  158.  "XOS_File",23,OurFile$ 
  159.  Ob%,,,,Size%,,Type% ;Flags%
  160. h-               
  161.  (Flags% 
  162.  %1) 
  163.  Ob%<>1 
  164. i.                 
  165. pe("Bad clipboard file")
  166.                
  167. k#                 block!36=Size%
  168. l#                 block!40=Type%
  169. m<                 
  170.  "Wimp_SendMessage",17,block,Request%
  171.                
  172.              
  173.  3   : 
  174.  (block!12)=SaveRef% 
  175. q&               
  176.  SaveDragTo%<>-1 
  177. r*                 SaveDragFrom%=block!4
  178. s)                 SaveFromRef%=block!8
  179. u&                 
  180.  Ack the message
  181. v'                 block!12 = block!8
  182. wD                 
  183.  "Wimp_SendMessage", 19, block, SaveDragFrom%
  184. yJ                 block!12=SaveDragRef% : 
  185.  Pass message on to dest app
  186. z?                 
  187.  "Wimp_SendMessage",18,block,SaveDragTo%
  188. {)                 SaveDragRef%=block!8
  189. |6                 
  190. proto("Asking app to load data")
  191.                
  192.              
  193. #               
  194. claim_clipboard
  195. ,               OurFile$=
  196. strip(block+44)
  197. (               
  198. set_text(3,OurFile$)
  199. :               
  200. set_text(6,"Clipboard"):Owner%=Handle%
  201. %               
  202. proto("I own it")
  203. #               Type$=
  204. ~block!40
  205. ,               
  206. set_text(2,
  207. type(Type$))
  208. 3               
  209. set_ind(0,"sfile_"+Type$+";r2")
  210. D               
  211.  "Wimp_GetCaretPosition",,block                
  212. G               
  213.  block!0=MainWindow% 
  214.  block!0=-1:
  215. put_caret(block)
  216. 6               
  217. unshade(3):
  218. unshade(0):
  219. unshade(4)
  220. >               
  221. unshade(6):
  222. unshade(2):
  223. front(MainWindow%)
  224.              
  225.  4   : 
  226.  SaveDragTo%<>-1 
  227. (               block!12=SaveFromRef%
  228. ?               
  229.  "Wimp_SendMessage",17,block,SaveDragFrom%
  230. !               SaveDragTo%=-1
  231.              
  232.  &F  : 
  233.  ((block!20) 
  234. D               
  235.  block!4<>Handle% 
  236.  Owner%=-1:
  237. examine_clipboard
  238.              
  239.  &10 : 
  240.  MyRef%<>block!8 
  241. %               
  242.  Owner%=Handle% 
  243. 2                 
  244. proto("Sending data myself")
  245. %                 Request%=block!4
  246. %                 block!12=block!8
  247. 3                 
  248.  "Wimp_SendMessage",19,block
  249. L                 
  250.  "XOS_File",23,OurFile$ 
  251.  Ob%,,,,Size%,,Type% ;Flags%
  252. /                 
  253.  (Flags% 
  254.  %1) 
  255.  Ob%<>1 
  256. 4                   
  257. report("Bad clipboard file")
  258.                  
  259. %                   block!36=Size%
  260. !                   block!16=1
  261. %                   block!40=Type%
  262. ,                   Leaf$=
  263. leaf(OurFile$)
  264. +                   $(block+44)=Leaf$+
  265. 2                   block!0=44+(
  266. (Leaf$)+4)
  267. >                   
  268.  "Wimp_SendMessage",17,block,Request%
  269.                  
  270.                
  271.              
  272.  block!16=4 
  273. pe("Receiver died!"):SaveDragTo%=-1:
  274.  block!8=SaveDragRef% 
  275. proto("App not interested"):
  276.  block!8<>MyRef% 
  277.  block!16<>&10 
  278. set_text(3,"None")
  279. set_text(6,"-"):Owner%=-1:
  280. proto("No clipboard")
  281. set_text(2,"-")
  282. Type$="xxx"
  283. set_ind(0,"sfile_xxx;r2")
  284.  "Wimp_GetCaretPosition",,block                
  285.  block!0=MainWindow% 
  286.  block!0=-1:
  287. put_caret(block)
  288. shade(3):
  289. shade(0):
  290. shade(4)
  291. unshade(6):
  292. unshade(2)
  293. examine_clipboard
  294.  Owner%=Handle% 
  295. block!0=44
  296. block!12=0
  297. block!16=&10
  298. block!20=MainWindow%
  299. ;block!24=InternalHandle% : 
  300.  Help find protocol errors.
  301. block!36=4
  302. block!40=-1
  303.  "Wimp_SendMessage",18,block,0
  304. MyRef%=block!8
  305. proto("Looking for owner")
  306. put_caret(b)
  307.  "Wimp_SetCaretPosition",b!0,b!4,b!8,b!12,b!16,b!20
  308. name(Handle%)
  309.  "XTaskManager_TaskNameFromHandle",Handle% 
  310.  NamePtr% ;Flags%
  311.  Flags% 
  312.  ="???"
  313. strip(NamePtr%)
  314. strip(Addr%)
  315.     A$=""
  316.  ?Addr%>31
  317.   A$+=
  318. (?Addr%)
  319.   Addr%+=1
  320. set_text(Icon%,Text$)
  321. block!512=MainWindow%
  322. block!516=Icon%
  323.  "Wimp_GetIconState",,block+512
  324. Addr%=block!(28+512)
  325. Size%=block!(36+512)
  326. $Addr%=
  327. Text$,Size%-1)
  328. read_data(Icon%)
  329. block!512=MainWindow%
  330. block!516=Icon%
  331.  "Wimp_GetIconState",,block+512
  332. strip(block!(28+512))
  333. set_ind(Icon%,Text$)
  334. (Text$)<>12 
  335.  Text$="sfile_xxx;r2"
  336. block!512=MainWindow%
  337. block!516=Icon%
  338.  "Wimp_GetIconState",,block+512
  339. Addr%=block!(32+512)
  340. $Addr%=Text$
  341. type(Hex$)
  342.  "XOS_ReadVarVal","File$Type_"+Hex$,block+512,512,0,3 
  343.  ,,Len%;Flags%
  344.  Flags% 
  345.  =Hex$
  346. block?(Len%+512)=0
  347. strip(block+512)
  348. mouse_click
  349. Window%=block!12
  350.  Window% 
  351.  -2         : 
  352. toggle(MainWindow%)
  353.  MainWindow%: 
  354.  block!16=4 
  355. save_clipboard(
  356. read_data(3),-1,0)
  357. 4                    
  358.  block!16=0 
  359. drag_icon(0)
  360.  InfoWindow%: block!0=InfoWindow%
  361. !                    block!4=1
  362. 0                    
  363.  "Wimp_DragBox",,block
  364.  block!12=-2 
  365.  Height%=96+44*2 
  366.  Height%=block!4+48
  367.  "Wimp_CreateMenu",,menu_block,block!0-48,Height%
  368. front(Window%)
  369. block!512=Window%
  370.  "Wimp_GetWindowState",,block+512
  371. block!(512+28)=-1
  372.  "Wimp_OpenWindow",,block+512
  373. put_caret_in(3)
  374. close(Window%)
  375. block!512=Window%
  376.  "Wimp_CloseWindow",,block+512
  377. toggle(Window%)
  378. block!512=Window%
  379.  "Wimp_GetWindowState",,block+512
  380.  block!(512+32) 
  381.  (1<<17) 
  382.  "Wimp_CloseWindow",,block+512
  383.   block!(512+28)=-1
  384.  "Wimp_OpenWindow",,block+512
  385. put_caret_in(3)
  386. examine_clipboard
  387. shade(Icon%)
  388. block!512=MainWindow%
  389. block!516=Icon%
  390. block!520=1<<22
  391. block!524=1<<22
  392.  "Wimp_SetIconState",,block+512
  393. unshade(Icon%)
  394. block!512=MainWindow%
  395. block!516=Icon%
  396. block!520=0
  397. block!524=1<<22
  398.  "Wimp_SetIconState",,block+512
  399. claim_clipboard
  400. bk=block+512
  401. !bk=24
  402. bk!12=0
  403. bk!16=&f
  404. bk!20=%100
  405.  "Wimp_SendMessage",18,bk,0
  406. report(Error$)
  407. block!512=0
  408. $(block+516)=Error$
  409.  "Wimp_ReportError",block+512,%101,"Clipboard"
  410. leaf(Text$)
  411. Dot%=0
  412.  A%=1 
  413. (Text$)
  414. Text$,A%,1)="." 
  415.  Dot%=A%
  416. Text$,Dot%+1)
  417. save_clipboard(S$,Check%,UseWindow%)
  418. SavePath$=S$
  419.  Check% 
  420. SavePath$,".")=0 
  421. report("To save, drag icon to a directory viewer"):
  422.  Owner%=Handle% 
  423. copy(OurFile$, SavePath$):
  424. block!0=44
  425. block!12=0
  426. P+block!16=&10 : 
  427.  Request clipboard data
  428.  UseWindow% = 
  429.   block!20=-3
  430.   block!24=InternalHandle%
  431.   block!28=640
  432.   block!32=512
  433. block!36=4
  434. block!40=-1
  435.  "Wimp_SendMessage",18,block,Owner%
  436. SaveRef%=block!8
  437. proto("Asking owner to save")
  438. save_ack_to(Path$)
  439. Request%=block!4
  440. block!12=block!8
  441. a0block!16=2 : 
  442.  Please save file to SavePath$
  443. $(block+44)=SavePath$+
  444. c#block!0=(
  445. (SavePath$)+48) 
  446.  "Wimp_SendMessage",17,block,Request%
  447. SaveRef%=block!8
  448. put_caret_in(Icon%)
  449. block!512=MainWindow%
  450. block!516=Icon%
  451.  "Wimp_GetIconState",,block+512
  452.  block!(512+24) 
  453.  (1<<22) 
  454.  "Wimp_SetCaretPosition",MainWindow%,Icon%,&10000,0,-1,-1
  455. drag_icon(Icon%)
  456. bk=block+512
  457. bk!0=MainWindow%
  458. bk!4=Icon%
  459.  "Wimp_GetIconState",,bk
  460. MinX%=bk!8
  461. MinY%=bk!12
  462. MaxX%=bk!16
  463. MaxY%=bk!20
  464.  "Wimp_GetWindowState",,bk
  465. Xoff%=bk!4
  466. bk!0=MinX%+Xoff%
  467. bk!4=MinY%+bk!16
  468. bk!8=MaxX%+Xoff%
  469. bk!12=MaxY%+bk!16
  470.  "DragASprite_Start",%11000101,1,"file_"+Type$,bk
  471. user_drag_box
  472.  "DragASprite_Stop"
  473.  "Wimp_GetPointerInfo",,block
  474.  block!12=MainWindow% 
  475. DestWin%=block!12
  476. DestIcon%=block!16
  477. Name$=
  478. leaf(
  479. read_data(3))
  480. block!28=block!0
  481. block!32=block!4
  482. block!0=(48+
  483. (Name$)) 
  484. block!12=0
  485. 4block!16=1 : 
  486.  Ask dest app if it wants the file
  487. block!20=DestWin%
  488. block!24=DestIcon%
  489. block!36=0
  490. block!40=
  491. ("&"+Type$)
  492. $(block+44)=Name$+
  493.  "Wimp_SendMessage",18,block,DestWin%,DestIcon% 
  494.  ,,SaveDragTo%
  495. SaveDragRef%=block!8
  496. proto("Offering data")
  497. send_save_ack
  498. block!12=SaveDragRef%
  499. )block!16=3 : 
  500.  File can now be loaded
  501.  "Wimp_SendMessage",17,block,SaveDragTo%
  502. SaveDragTo%=-1
  503. init_menu
  504. $menu_block="Clipboard"+
  505. menu_block!12=&070207
  506. menu_block!16=16*7
  507. menu_block!20=44
  508. menu_block!24=0
  509. menu_block!28=0
  510. menu_block!32=InfoWindow%
  511. menu_block!36=&07000031
  512. $(menu_block+40)="Info"
  513. menu_block!52=&80
  514. menu_block!56=-1
  515. menu_block!60=&07000031
  516. $(menu_block+64)="Quit"
  517. copy(From$, To$)
  518.  "XOS_FSControl", 26, From$, To$, %10 
  519.  r0 ;v%
  520.  "Wimp_ReportError", r0, %101, "Clipboard" 
  521.  Report a protocol error
  522. pe(Error$)
  523. scrap!0 = MainWindow%
  524. scrap!4 = 7
  525.  "Wimp_GetIconState", 0, scrap
  526. $(scrap!28) = Error$
  527. scrap!8 =  &0b000000
  528. scrap!12 = &0f000000
  529.  "Wimp_SetIconState", 0, scrap
  530.  "Wimp_GetWindowState", 0, scrap
  531.  scrap!32 
  532.  (1 << 16) 
  533.  Window is already open - bring it to the front
  534.  and enlarge it to show the error.
  535.   scrap!8 -= 128
  536.   scrap!28 = -1
  537.  "Wimp_OpenWindow", 0, scrap
  538. proto(Mess$)
  539. scrap!0 = MainWindow%
  540. scrap!4 = 7
  541.  "Wimp_GetIconState", 0, scrap
  542. $(scrap!28) = Mess$
  543. scrap!8 =  &07000000
  544. scrap!12 = &0f000000
  545.  "Wimp_SetIconState", 0, scrap
  546.